<html>
<head>
<style>
  #plugin {
    width: 150px;
    height: 150px;
  }
</style>
</head>

<body onload="test();">

<embed id="plugin_drag" type="application/x-webkit-test-webplugin" can-process-drag="true" contentEditable="false"></embed>
<embed id="plugin_editable" type="application/x-webkit-test-webplugin" contentEditable="true"></embed>
<embed id="plugin" type="application/x-webkit-test-webplugin"></embed>
<div id='text'><span>Some text to drag</span></div>
<script>

function dragOverPlugin(plugin) {
    var div = document.getElementById('text');
    div.focus();
    getSelection().collapse(div, 0);
    getSelection().modify('extend', 'forward', 'word');

    console.log("Dragging over " + plugin.id);
    var positionX = plugin.offsetLeft + plugin.offsetWidth / 2;
    var positionY = plugin.offsetTop + plugin.offsetHeight / 2;

    var startX = div.offsetLeft + div.firstChild.offsetWidth / 5;
    var startY = div.offsetTop + div.offsetHeight / 2;;

    // Drag into the plugin and drag out before dropping.
    eventSender.dragMode = true;
    eventSender.mouseMoveTo(startX, startY);
    eventSender.mouseDown();
    eventSender.leapForward(250);
    eventSender.mouseMoveTo(positionX, positionY);
    eventSender.mouseMoveTo(positionX + 2, positionY);
    eventSender.mouseMoveTo(startX, startY);
    eventSender.mouseMoveTo(positionX, positionY);
    eventSender.mouseUp();
    eventSender.leapForward(250);
    eventSender.mouseMoveTo(startX, startY);
}

function test() {
    if (!window.testRunner || !window.eventSender) {
        document.write("This test does not work in manual mode.");
    } else {
        testRunner.dumpAsText();
        dragOverPlugin(plugin_drag);
        dragOverPlugin(plugin_editable);
        dragOverPlugin(plugin);
    }
}
</script>
</body>
</html>
